package com.treeroot.treenet.protocol.help;


import java.io.IOException;
import java.io.InputStream;
import java.nio.CharBuffer;

/**
 * Create By TreeRoot
 * Create Time: 2023/12/18 03:42
 * Class Name: ByteBufferInputStream
 * Description:
 * ByteBufferInputStream 将 CharBuffer 封装为 InputStream
 * @author TreeRoot
 */
public  class ByteBufferInputStream extends InputStream {
    private final CharBuffer charBuffer;

    public ByteBufferInputStream(CharBuffer charBuffer) {
        this.charBuffer = charBuffer;
    }

    @Override
    public int read() throws IOException {
        if (!charBuffer.hasRemaining()) {
            return -1;
        }
        return charBuffer.get();
    }
}
